﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using XChipTool.Enties;
using XChip_Common;
using System.IO;
using System.Configuration;
using SerialPortHelperLib;
using System.IO.Ports;

namespace XChipTool
{
    public partial class XChip_SettingFile : DevExpress.XtraEditors.XtraForm
    {
        #region 全局变量

        int type = 0;
        //bindriving BinDri;
        bincurrency BinCur;
        bindefault BinDef;
        //private int Id = -1;
        private string GuidNo;
        List<List<TreeListValue>> SettingList = new List<List<TreeListValue>>();
        public bincurrencyManager Bincurrency_BLL = new bincurrencyManager();
        public delegate void SendEventBinSettingNewClick(string list);

        public event SendEventBinSettingNewClick SendBinSetClick;
        bool isloadAgain = false;//是否再次加载标志 
        public bool isNumFirst = false;//是否是编号优先
        public bool isPollingSetOk = false;//轮询setting是否ok的标志
        public bool isOsdTemp = false;
        public bool isOsdVerCheck = false;//勾选版本号
        bool beginMove = false;
        int currentXPosition;
        int currentYPosition;

        public SerialPort sPortTemp;

        List<TreeListValue> commonList = new List<TreeListValue>();

        #endregion
        public XChip_SettingFile()
        {
            InitializeComponent();
        }

        public XChip_SettingFile(int _type, bincurrency binmodel, bindefault binD, string guid,bool isNum, bool ispolling,SerialPort _sPortTemp,bool _isOsd=false,bool _isOsdVerCheck=false)
        {
            InitializeComponent();
            type = _type;
            BinCur = binmodel;
            BinDef = binD;
            GuidNo = guid;
            isNumFirst = isNum;
            SetNumFirst(isNum, 0);
            sPortTemp = _sPortTemp;
            toolTipC.AutoPopDelay = 5000;
            toolTipC.InitialDelay = 0;
            toolTipC.ReshowDelay = 500;
            isPollingSetOk = ispolling;
            isOsdTemp = _isOsd;
            isOsdVerCheck = _isOsdVerCheck;
            toolTipC.Appearance.ForeColor = Color.Tomato;
            if (!isPollingSetOk)
            {
                toolTipC.SetToolTip(setting0_btn, "硬件pin脚 setting_sel 拉低，上电时才能boot setting0");
                toolTipC.SetToolTip(setting1_btn, "硬件pin脚 setting_sel 拉高，上电时才能boot setting1");
            }
        }

         void SetNumFirst(bool isNum,int Num) {
            panelNum.Visible = isNum;
            if (!isNum) return;
            List<TreeListValue> listNum = new List<TreeListValue>();
            for (int i = 0; i < 32; i++)
            {
                listNum.Add(new TreeListValue() { ValueMember = i.ToString(), DisplayMember = i.ToString() });
            }
            lookUpNum.Properties.DataSource = listNum;
            lookUpNum.ItemIndex = Num;
        }

        private void XChip_SettingFile_Load(object sender, EventArgs e)
        {
            //navigationPane1.SelectedPage = navigationPage2;
            //navigationPane1.SelectedPage = navigationPage1;
            //SettingList_Help.SetTips = new List<SettingTips>();
            //初始化文件16个文件
            for (int i = 0; i < 16; i++)
            {
                SettingList.Add(new List<TreeListValue>());
            }
            onetofourPage.PageVisible = true;
            fivetoeightPage.PageVisible = false;
            ninetotwelvePage.PageVisible = false;
            thirteentosixteenPage.PageVisible = false;

            textEdit1.Enabled = isPollingSetOk;//控制数目是否可调
            
            cmb_Polling_Pin_Select.Enabled = isPollingSetOk; //控制是否可调
            
            if ( SettingList_Help.SetTips16.Count>0&& !string.IsNullOrEmpty(SettingList_Help.SetTips16[0].Tips))
            {
                textEdit1.Text = SettingList_Help.SetTips16[0].SettingNo;
                cmb_Polling_Pin_Select.Text = SettingList_Help.SetTips16[0].Tips;
            }
            
            for (int i = 0; i < 16; i++)
            {
                isloadAgain = true;
                var str = $"setting{i}";
                var strc = $"common{i}";
                Control c = this.Controls.Find(str, true)[0];
                Control cc = this.Controls.Find(strc, true)[0];
                LookUpEdit seting = c as LookUpEdit;
                if (!string.IsNullOrEmpty(SettingList_Help.SetTips16[i].Tag))
                {
                    seting.Tag = SettingList_Help.SetTips16[i].Tag;
                }
                if (SettingList_Help.SetTips16.Count > 0 && SettingList_Help.SetTips16[i].data != null)
                {
                    seting.Properties.DataSource = SettingList_Help.SetTips16[i].data;
                    seting.ItemIndex = SettingList_Help.SetTips16[i].data.Count() - 1;
                   
                   
                }
               
                LookUpEdit common = cc as LookUpEdit;
                if (!string.IsNullOrEmpty(SettingList_Help.SetTips16[i].Tag))
                {
                    seting.Tag = SettingList_Help.SetTips16[i].Tag;
                }
                if (SettingList_Help.SetTips16.Count > 0 && SettingList_Help.SetTips16[i].comData != null)
                {
                    common.Properties.DataSource = SettingList_Help.SetTips16[i].comData;
                    common.ItemIndex = SettingList_Help.SetTips16[i].comData.Count() - 1;
                    
                }
                
                isloadAgain = false;
            }

        
            if (lookUpNum.ItemIndex < 0)
                lookUpNum.ItemIndex = 0;
            //HideControl();

            #region 配置提示
            toolTipC.AutoPopDelay = 5000;
            toolTipC.InitialDelay = 0;
            toolTipC.ReshowDelay = 500;
            var iqStr = "更新整个setting参数值";
            var osStr = "只更新10.1 IQ_common参数值";
            if (!isPollingSetOk)
            {
                toolTipC.SetToolTip(common0_all_btn, iqStr);
                toolTipC.SetToolTip(common1_all_btn, iqStr);
                toolTipC.SetToolTip(common2_all_btn, iqStr);
                toolTipC.SetToolTip(common3_all_btn, iqStr);

                toolTipC.SetToolTip(setting0_all_btn, iqStr);
                toolTipC.SetToolTip(setting1_all_btn, iqStr);
                toolTipC.SetToolTip(setting2_all_btn, iqStr);
                toolTipC.SetToolTip(setting3_all_btn, iqStr);

                toolTipC.SetToolTip(setting0_iq_btn, osStr);
                toolTipC.SetToolTip(setting1_iq_btn, osStr);
                toolTipC.SetToolTip(setting2_iq_btn, osStr);
                toolTipC.SetToolTip(setting3_iq_btn, osStr);
            }

            ////IQ_ComBtn
            //toolTipC.SetToolTip(IQ_ComBtn, osStr);
            #endregion

            if (isPollingSetOk)
            {
                setPanelShowHide(3);
                textEdit1.Text = "3"; //轮询必须放三套 跟gpio冲突 
            }
            else {
                setPanelShowHide(2);
                textEdit1.Text = "2"; //轮询必须放三套 跟gpio冲突 
            }
        }
        /// <summary>
        /// 打开文件
        /// </summary>
        /// <param name="openFile">文件路径</param>
        /// <returns></returns>
        public string OpenSettingToFile(string openFile)
        {
            string pSavePath = string.Format("{0}\\Lib\\xc{1}_setting\\", Application.StartupPath, ConfigurationManager.AppSettings["xcVersion"]);
            string pLocalName = System.IO.Path.GetFileName(openFile); //获取文件名
            string path = pSavePath + "\\Flash_" + Path.GetFileNameWithoutExtension(pLocalName) + ".txt";

            //增加是否有轮询
            var rList = Setting2Help.ReadTextFileToList(openFile);
            if (isPollingSetOk)
            {
                rList.AddRange(ParaHelp.CreateBinPressKey());
                uint pin = Convert.ToUInt16(ParaHelp.Bin_Press_Key.Find(p => p.PKey == "0x0b38").PValue, 16);
                List<string[]> tempList = new List<string[]>();
                #region 解析rlist存入tempList
                string addrPageH = "80";
                string addrPageM = string.Empty;
                foreach (string line in rList)
                {
                    string[] temp = new string[3];
                    temp[0] = line;
                    string[] col = line.ToLower().Replace('，', ',').Split(',');
                    string colFirst = col.First().Trim();
                    if (col.Count() > 2)
                    {
                        if (colFirst == "0xfffd")
                        {
                            addrPageH = col[1].Replace("0x", "").Trim();
                        }
                        else if (colFirst == "0xfffe")
                        {
                            addrPageM = col[1].Replace("0x", "").Trim();
                        }
                        else if (colFirst.Contains("0x") && !colFirst.Contains("//"))
                        {
                            temp[1] = addrPageH + addrPageM + colFirst.Replace("0x", "").Replace(" ", "");
                            temp[2] = col[1].Replace("0x", "").Replace(" ", "");
                        }
                    }
                    tempList.Add(temp);
                }
                #endregion
                #region 更新寄存器方法
                Action<string, string> tempUpReg = new Action<string, string>(
                             (string addr, string value) =>
                             {
                                 string tempstr = tempList.LastOrDefault(c => c[1] == addr).First();
                                 string[] tempStrArray = tempstr.Replace("，", ",").Split(',');
                                 tempStrArray[1] = value;
                                 tempList.Last(c => c[1] == addr)[0] = string.Join(",", tempStrArray);
                             });
                #endregion
                string gpio8_15_en = tempList.LastOrDefault(c => c[1] == "80500201")?.GetValue(2).ToString();
                string gpio8_15_dir = tempList.LastOrDefault(c => c[1] == "80500205")?.GetValue(2).ToString();
                string gpio8_15_in_en = tempList.LastOrDefault(c => c[1] == "805000d1")?.GetValue(2).ToString();
                switch (pin)
                {
                    #region 更新按键轮询所选gpio相关寄存器
                    case 0://Gpio 2
                        string gpio0_7_en = tempList.LastOrDefault(c => c[1] == "80500200")?.GetValue(2).ToString();
                        string gpio0_7_dir = tempList.LastOrDefault(c => c[1] == "80500204")?.GetValue(2).ToString();
                        string gpio0_7_in_en = tempList.LastOrDefault(c => c[1] == "805000d0")?.GetValue(2).ToString();
                        if (string.IsNullOrEmpty(gpio0_7_en) || string.IsNullOrEmpty(gpio0_7_dir) || string.IsNullOrEmpty(gpio0_7_in_en))
                        {
                            tempList.Add(new string[3] { "0xfffd,0x80,\r\n0xfffe,0x50,", null, null });
                        }
                        if (string.IsNullOrEmpty(gpio0_7_en))
                        {
                            tempList.Add(new string[3] { "0x0200,0x04,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio0_7_en, 16);
                            tempUpReg("80500200", "0x" + (tempVal | 0x04).ToString("x2"));
                        }
                        if (string.IsNullOrEmpty(gpio0_7_dir))
                        {
                            tempList.Add(new string[3] { "0x0204,0x00,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio0_7_dir, 16);
                            tempUpReg("80500204", "0x" + (tempVal & 0xfb).ToString("x2"));
                        }
                        if (string.IsNullOrEmpty(gpio0_7_in_en))
                        {
                            tempList.Add(new string[3] { "0x00d0,0x04,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio0_7_in_en, 16);
                            tempUpReg("805000d0", "0x" + (tempVal | 0x04).ToString("x2"));
                        }
                        break;
                    case 1://Gpio 8                           
                        if (string.IsNullOrEmpty(gpio8_15_en) || string.IsNullOrEmpty(gpio8_15_dir) || string.IsNullOrEmpty(gpio8_15_in_en))
                        {
                            tempList.Add(new string[3] { "0xfffd,0x80,\r\n0xfffe,0x50,", null, null });
                        }
                        if (string.IsNullOrEmpty(gpio8_15_en))
                        {
                            tempList.Add(new string[3] { "0x0201,0x01,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio8_15_en, 16);
                            tempUpReg("80500201", "0x" + (tempVal | 0x01).ToString("x2"));
                        }
                        if (string.IsNullOrEmpty(gpio8_15_dir))
                        {
                            tempList.Add(new string[3] { "0x0205,0x00,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio8_15_dir, 16);
                            tempUpReg("80500205", "0x" + (tempVal & 0xfe).ToString("x2"));
                        }
                        if (string.IsNullOrEmpty(gpio8_15_in_en))
                        {
                            tempList.Add(new string[3] { "0x00d1,0x01,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio8_15_in_en, 16);
                            tempUpReg("805000d1", "0x" + (tempVal | 0x01).ToString("x2"));
                        }
                        break;
                    case 2://Gpio 9
                        if (string.IsNullOrEmpty(gpio8_15_en) || string.IsNullOrEmpty(gpio8_15_dir) || string.IsNullOrEmpty(gpio8_15_in_en))
                        {
                            tempList.Add(new string[3] { "0xfffd,0x80,\r\n0xfffe,0x50,", null, null });
                        }
                        if (string.IsNullOrEmpty(gpio8_15_en))
                        {
                            tempList.Add(new string[3] { "0x0201,0x02,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio8_15_en, 16);
                            tempUpReg("80500201", "0x" + (tempVal | 0x02).ToString("x2"));
                        }
                        if (string.IsNullOrEmpty(gpio8_15_dir))
                        {
                            tempList.Add(new string[3] { "0x0205,0x00,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio8_15_dir, 16);
                            tempUpReg("80500205", "0x" + (tempVal & 0xfd).ToString("x2"));
                        }
                        if (string.IsNullOrEmpty(gpio8_15_in_en))
                        {
                            tempList.Add(new string[3] { "0x00d1,0x02,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio8_15_in_en, 16);
                            tempUpReg("805000d1", "0x" + (tempVal | 0x02).ToString("x2"));
                        }
                        break;
                    case 3://Gpio 22
                        string gpio16_23_en = tempList.LastOrDefault(c => c[1] == "80500202")?.GetValue(2).ToString();
                        string gpio16_23_dir = tempList.LastOrDefault(c => c[1] == "80500206")?.GetValue(2).ToString();
                        string gpio16_23_in_en = tempList.LastOrDefault(c => c[1] == "805000d2")?.GetValue(2).ToString();
                        int x = tempList.FindLastIndex(c => c[1] == "805000d2");
                        if (string.IsNullOrEmpty(gpio16_23_en) || string.IsNullOrEmpty(gpio16_23_dir) || string.IsNullOrEmpty(gpio16_23_in_en))
                        {
                            tempList.Add(new string[3] { "0xfffd,0x80,\r\n0xfffe,0x50,", null, null });
                        }
                        if (string.IsNullOrEmpty(gpio16_23_en))
                        {
                            tempList.Add(new string[3] { "0x0202,0x40,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio16_23_en, 16);
                            tempUpReg("80500202", "0x" + (tempVal | 0x40).ToString("x2"));
                        }
                        if (string.IsNullOrEmpty(gpio16_23_dir))
                        {
                            tempList.Add(new string[3] { "0x0206,0x00,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio16_23_dir, 16);
                            tempUpReg("80500206", "0x" + (tempVal & 0xbf).ToString("x2"));
                        }
                        if (string.IsNullOrEmpty(gpio16_23_in_en))
                        {
                            tempList.Add(new string[3] { "0x00d2,0x40,", null, null });
                        }
                        else
                        {
                            uint tempVal = Convert.ToUInt16(gpio16_23_in_en, 16);
                            tempUpReg("805000d2", "0x" + (tempVal | 0x40).ToString("x2"));
                        }
                        break;
                    #endregion
                    default:
                        break;
                }
                rList = tempList.Select(c => c[0]).ToList();
            }
            else {
                //添加轮询使能开关
                rList.Add("0xfffd,0x80,");
                rList.Add("0xfffe,0x14,");
                rList.Add("0x0b1e,0x00,");
            }
            if (isOsdTemp)
            {
                rList.Add($"0xfffe,0x14,");
                rList.Add($"0x08a6,0x01,//温度显示使能开关");
            }
            if (isOsdVerCheck)
            {
                rList.AddRange(ParaHelp.CreateOsdVersionInfo());
            }
           
            string openpath = System.IO.Path.GetDirectoryName(pSavePath) + "\\Temp_" + Path.GetFileNameWithoutExtension(pLocalName) + ".txt";
            File.WriteAllLines(openpath, rList.ToArray());
            Setting2Help.FlashSetting2Flash(openpath, path,1,0,0); //测试模式下 Usage FPGA  选择0； --东东发布的时候改 现在这个给你用
            return path;
        }

      
        #region 更改编号 更新数据库
        /// <summary>
        /// 更改编号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lookUpNum_EditValueChanged(object sender, EventArgs e)
        {
            var model99 = Bincurrency_BLL.GetList(c => c.GuidId == GuidNo);
            if (!model99.Exists(c => c.BinId == 112 && c.SerialNo == 0 && c.GuidId == GuidNo)) //binid 写死112
            {
                var mode102 = new bincurrency();
                mode102.GuidId = GuidNo;
                mode102.BinId = 112;
                mode102.BinAddressNo = lookUpNum.Text;
                mode102.BinAddressOutName = $"{lookUpNum.Text}.txt";
                mode102.SortOrder = 0;
                mode102.IsModified = (mode102.SortOrder == 0 ? 0 : 1);
                Bincurrency_BLL.Insert(mode102);
            }
            else {
                //更新
                var model = model99.First(c => c.BinId == 112 && c.SerialNo == 0 && c.GuidId == GuidNo);
                model.BinAddressNo = lookUpNum.Text;
                model.BinAddressOutName = $"{lookUpNum.Text}.txt";
                Bincurrency_BLL.Update(model);
            }
        }
        #endregion

        private void XChip_SettingFile_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                beginMove = true;
                currentXPosition = MousePosition.X;
                currentYPosition = MousePosition.Y;
            }
        }

        private void XChip_SettingFile_MouseMove(object sender, MouseEventArgs e)
        {
            if (beginMove)
            {
                this.Left += MousePosition.X - currentXPosition;
                this.Top += MousePosition.Y - currentYPosition;
                currentXPosition = MousePosition.X;
                currentYPosition = MousePosition.Y;
            }
        }

        private void XChip_SettingFile_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                currentXPosition = 0;
                currentYPosition = 0;
                beginMove = false;
            }
        }

        private void XChip_SettingFile_FormClosed(object sender, EventArgs e)
        {

            SettingList_Help.SetTips16[0].SettingNo = textEdit1.Text;
            SettingList_Help.SetTips16[0].Tips = cmb_Polling_Pin_Select.Text;
            //是否勾选了轮询
            if (isPollingSetOk)
            {
                Bincurrency_BLL.Delete(c => c.BinId == 112&&c.SortOrder>0);
                ParaHelp.Bin_Press_Key.Find(p => p.PKey == "0x0b38").PValue = $"0x{cmb_Polling_Pin_Select.SelectedIndex.ToString("x2").PadLeft(2, '0')}";
                ParaHelp.Bin_Press_Key.Find(p => p.PKey == "0x0b20").PValue = $"0x{int.Parse(textEdit1.Text).ToString("x2").PadLeft(2, '0')}";
                int pNo = 0;
                for (int i = 0x0b21, j = 0; i < 0x0b21 + int.Parse(textEdit1.Text); i++, j++)
                {
                    string a = $"0x{i.ToString("x4")}";
                    ParaHelp.Bin_Press_Key.Find(p => p.PKey == a).PValue = $"0x{(pNo++).ToString("x2").PadLeft(2, '0')}";
                }

                for (int i = 0; i < int.Parse(textEdit1.Text); i++)
                {
                    var str = $"setting{i}";
                    var strc = $"common{i}";
                    Control c = this.Controls.Find(str, true)[0];
                    Control cc = this.Controls.Find(strc, true)[0];
                    LookUpEdit seting = c as LookUpEdit;
                    if (null == seting.EditValue || string.IsNullOrEmpty(seting.EditValue.ToString()) || seting.Text.Contains("请"))
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"请选择{str}文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    LookUpEdit common = cc as LookUpEdit;
                    if (null == common.EditValue || string.IsNullOrEmpty(common.EditValue.ToString()) || common.Text.Contains("请"))
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"请选择{strc}文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

            }
            else {
                Bincurrency_BLL.Delete(c => c.BinId == 112&&c.SortOrder>= 2);
            }
            for (int i = 0; i < int.Parse(textEdit1.Text); i++)
            {
                var str = $"setting{i}";
                var strc = $"common{i}";
                Control cb = this.Controls.Find(str, true)[0];
                Control cc = this.Controls.Find(strc, true)[0];
                LookUpEdit seting = cb as LookUpEdit;
                LookUpEdit common = cc as LookUpEdit;


               

                if (isPollingSetOk)
                {
                    string pathName = seting.EditValue.ToString();
                    List<string> AList = File.ReadAllLines(pathName, Encoding.Default).ToList();
                    List<string> BList = File.ReadAllLines(common.EditValue.ToString(), Encoding.Default).ToList();
                    int aStartIndex = AList.FindIndex(c => c.Contains("xchip_i2c_bypass_on_regs"));
                    if (aStartIndex == -1 && !isPollingSetOk)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"选择setting文件:{pathName}格式错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    int bStartIndex = BList.FindIndex(c => c.Contains("#region config"));
                    if (bStartIndex == -1 && !isPollingSetOk)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"选择common文件格式错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    string pSavePath = string.Format("{0}\\Lib\\xc{1}_setting\\", Application.StartupPath, ConfigurationManager.AppSettings["xcVersion"]);
                    string pLocalName = System.IO.Path.GetFileName(pathName); //获取文件名
                    string path = pSavePath + $"\\IQCom_{ Path.GetFileNameWithoutExtension(pLocalName)}_{i}_{AppHelper.GetTimeStamp()}.txt";
                    FileHelper.ComMergeFiles(AList, BList, path, "xchip_i2c_bypass_on_regs", "#region config");
                    var commonPath = OpenSettingToFile(path);
                   
                    if (i == 0)
                    {
                        var modelBC1 = Bincurrency_BLL.GetSingle(c => c.GuidId == GuidNo && c.BinId == 112 && c.SerialNo == 0 && c.SortOrder == 0 );
                        modelBC1.IsModified = 0;
                        modelBC1.BinAddressNo = lookUpNum.Text;
                        modelBC1.BinAddressOutName = $"0.txt";
                        modelBC1.BinInPath = pathName;
                        modelBC1.BinInName = Path.GetFileName(pathName);
                        modelBC1.BinOutPath = commonPath;
                        modelBC1.BinOutName = Path.GetFileName(commonPath);
                        modelBC1.LengthAddress = HeaderHelper.FilePathLengthComplement(commonPath);
                        modelBC1.FileStatus = 2;
                        Bincurrency_BLL.Update(modelBC1);
                    }
                    else {
                        var modelBC2 = new bincurrency();
                        modelBC2.GuidId = GuidNo;
                        modelBC2.BinId = 112;
                        modelBC2.CreateTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        modelBC2.BinInPath = pathName;
                        modelBC2.BinInName = Path.GetFileName(pathName);
                        modelBC2.BinOutPath = commonPath;
                        modelBC2.BinOutName = Path.GetFileName(commonPath);
                        modelBC2.LengthAddress = HeaderHelper.FilePathLengthComplement(commonPath);
                        modelBC2.FileStatus = 2;
                        modelBC2.SerialNo = int.Parse(seting.Tag.ToString());
                        modelBC2.SortOrder = i;
                        Bincurrency_BLL.Insert(modelBC2);
                    }
                   
                }
                else {
                    if (seting.EditValue == null|| string.IsNullOrEmpty(seting.EditValue.ToString()) ||common.EditValue == null ||string.IsNullOrEmpty(common.EditValue.ToString()))
                    {
                        continue;
                    }
                    string pathName = seting.EditValue.ToString();
                    string orId = seting.Tag.ToString();
                    List<string> AList = File.ReadAllLines(pathName, Encoding.Default).ToList();
                    List<string> BList = File.ReadAllLines(common.EditValue.ToString(), Encoding.Default).ToList();
                    int aStartIndex = AList.FindIndex(c => c.Contains("xchip_i2c_bypass_on_regs"));
                    if (aStartIndex == -1 && !isPollingSetOk)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"选择setting文件:{pathName}格式错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    int bStartIndex = BList.FindIndex(c => c.Contains("#region config"));
                    if (bStartIndex == -1 && !isPollingSetOk)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"选择common文件格式错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    string pSavePath = string.Format("{0}\\Lib\\xc{1}_setting\\", Application.StartupPath, ConfigurationManager.AppSettings["xcVersion"]);
                    string pLocalName = System.IO.Path.GetFileName(pathName); //获取文件名
                    string path = pSavePath + $"\\IQCom_{ Path.GetFileNameWithoutExtension(pLocalName)}_{i}_{AppHelper.GetTimeStamp()}.txt";
                    FileHelper.ComMergeFiles(AList, BList, path, "xchip_i2c_bypass_on_regs", "#region config");
                    var commonPath = OpenSettingToFile(path);
                    var modelBC1 = Bincurrency_BLL.GetSingle(c => c.GuidId == GuidNo && c.BinId == 112&&c.SerialNo == 0 && c.SortOrder == 0&& string.IsNullOrEmpty( c.BinAddressOutName) );
                    if (modelBC1 !=null)
                    {
                        modelBC1.BinInPath = pathName;
                        modelBC1.BinInName = Path.GetFileName(pathName);
                        modelBC1.BinOutPath = commonPath;
                        modelBC1.BinOutName = Path.GetFileName(commonPath);
                        modelBC1.LengthAddress = HeaderHelper.FilePathLengthComplement(commonPath);
                        modelBC1.FileStatus = 2;
                        modelBC1.SerialNo = int.Parse(seting.Tag.ToString());
                        modelBC1.BinAddressNo = lookUpNum.Text;
                        modelBC1.BinAddressOutName = $"0.txt";
                        
                        Bincurrency_BLL.Update(modelBC1); 
                    }

                    var modelList = Bincurrency_BLL.GetList(c => c.GuidId == GuidNo && c.BinId == 112);
                    var modelMax = modelList.Where(c => c.BinId == 112).Max(c => c.SortOrder); //serialno 记录位置  sortorder记录排序
                    var modelBC = modelList.Find(c=>c.SerialNo == int.Parse(seting.Tag.ToString()));
                    if (null == modelBC)
                    {
                       
                       var  modelBC2 = new bincurrency();
                        modelBC2.GuidId = GuidNo;
                        modelBC2.BinId = 112;
                        modelBC2.CreateTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        modelBC2.BinInPath = pathName;
                        modelBC2.BinInName = Path.GetFileName(pathName);
                        modelBC2.BinOutPath = commonPath;
                        modelBC2.BinOutName = Path.GetFileName(commonPath);
                        modelBC2.LengthAddress = HeaderHelper.FilePathLengthComplement(commonPath);
                        modelBC2.FileStatus = 2;
                        modelBC2.SerialNo =int.Parse( seting.Tag.ToString());
                        modelBC2.SortOrder = modelMax+1;
                       
                        Bincurrency_BLL.Insert(modelBC2);
                    }
                    else {
                        modelBC.BinInPath = pathName;
                        modelBC.BinInName = Path.GetFileName(pathName);
                        modelBC.BinOutPath = commonPath;
                        modelBC.BinOutName = Path.GetFileName(commonPath);
                        modelBC.LengthAddress = HeaderHelper.FilePathLengthComplement(commonPath);
                        modelBC.FileStatus = 2;
                        modelBC.SerialNo = int.Parse(seting.Tag.ToString());
                       // modelBC.SortOrder = i;
                       
                        Bincurrency_BLL.Update(modelBC);
                    }

                }
                
            }

            if (null != SendBinSetClick)
            {
                SendBinSetClick(GuidNo);
            }
            this.Close();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private XChip_Common.MsgString<List<string>> UpdateParameterNewIQ(string filepath)
        {
            XChip_Common.MsgString<List<string>> msg = new MsgString<List<string>>();
            if (!sPortTemp.IsOpen)
            {
                msg.state = MsgSt.Warn;
                msg.msg = $"可用端口未打开！";
                return msg;
            }
            StreamReader sr = new StreamReader(filepath, Encoding.Default);
            List<string> listStr = new List<string>();
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                listStr.Add(line);
            }
            sr.Close();

            //WaitBefore.Start("参数导出", "正在加载中", 60);
            var Pe_patch_dal = new parameter_export_patchManager();
            var patchList = Pe_patch_dal.GetList();

            //全局变量 0xfffd  0xfffe
            string add = "80";//  0xfffd
            string addval = string.Empty; //0xfffe
            string duVal = string.Empty; //读取的值
            //IQ_common
            var commonStart = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("IQ_common", StringComparison.InvariantCultureIgnoreCase) >= 0);
            #region 判断IQ_common的起始索引
            if (commonStart < 0)
            {
                commonStart = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("AE sensor", StringComparison.InvariantCultureIgnoreCase) >= 0);
                if (commonStart < 0)
                {
                    commonStart = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("Step 10", StringComparison.InvariantCultureIgnoreCase) >= 0);
                }
            }
            #endregion
            //IQ_oneself
            var commonEnd = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("IQ_oneself", StringComparison.InvariantCultureIgnoreCase) >= 0);
            #region 判断setp2的起始索引
            if (commonEnd < 0)
            {
                commonEnd = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("avg_size", StringComparison.InvariantCultureIgnoreCase) >= 0);

            }
            #endregion
            if (commonStart == -1 || commonEnd == -1)
            {
                msg.state = MsgSt.Lose;
                msg.msg = $"无法找到指定更新位置，请先设置";
                return msg;
            }
            WaitBefore.Start("参数导出", "正在加载中", 60);
            SerialSend.isDebug = false;
            for (int i = commonStart; i < commonEnd; i++)
            {
                string[] col = listStr[i].Replace('，', ',').Split(',');
                if (col.Count() > 2)
                {
                    string colFirst = col.First().Trim().ToLower();
                    //过滤关键字
                    if (colFirst == "0xffff" || colFirst == "0xfff3" || colFirst == "0xfff6" || colFirst == "0xfff7" || colFirst == "0xfff8" || colFirst == "0xfff9" || colFirst == "0xfffa" || colFirst == "0xfff0" || colFirst == "0xfff1")
                    {
                        continue;
                    }
                    else if (colFirst == "0xfffd")
                    {
                        add = col[1].Replace("0x", "");
                    }
                    else if (colFirst == "0xfffe")
                    {
                        addval = col[1].Replace("0x", "");
                    }
                    else if (colFirst.Contains("0x") && !colFirst.Contains("//"))
                    {
                        try
                        {
                            string sonVal = colFirst.Replace("0x", "").Replace(" ", "");
                            duVal = (add + addval + sonVal.PadLeft(4, '0')).Replace("0x", "").Replace(" ", "").ToLower();
                            if (duVal.Length != 8 || duVal == "80300000" || duVal == "80300001" || duVal == "80300002" || duVal == "80300003" || duVal == "80300004"
                                     || duVal == "8014062c")
                                continue;

                            long tempVal = -1;

                            if (patchList.Count != 0 && patchList.Select(c => c.ReadAddr).Contains(duVal))
                            {
                                var patchModel = patchList.First(c => c.ReadAddr.Contains(duVal));
                                if (patchModel.ReadAddr == "80140226")
                                {

                                }
                                if (string.IsNullOrEmpty(patchModel.ConditionAddr) && string.IsNullOrEmpty(patchModel.RelationAddr) && !string.IsNullOrEmpty(patchModel.Val))
                                {
                                    tempVal = Convert.ToUInt32(patchModel.Val, 16);
                                }
                                else if (!string.IsNullOrEmpty(patchModel.ConditionAddr) && SerialSend.ReadRegister(Convert.ToUInt32(patchModel.ConditionAddr, 16), sPortTemp) == 0)
                                {
                                    tempVal = SerialSend.ReadRegister(Convert.ToUInt32(patchModel.ReadAddr, 16), sPortTemp);
                                }
                                else if (string.IsNullOrEmpty(patchModel.RelationAddr) && string.IsNullOrEmpty(patchModel.ConditionAddr) && !string.IsNullOrEmpty(patchModel.Bit))
                                {
                                    tempVal = Convert.ToUInt32(patchModel.Bit, 16);
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(patchModel.Bit) && patchModel.Bit.Contains("&0x7f"))
                                    {
                                        tempVal = SerialSend.ReadRegister(Convert.ToUInt32(patchModel.RelationAddr, 16), sPortTemp) & 0x7f;
                                    }
                                    else
                                    {
                                        tempVal = SerialSend.ReadRegister(Convert.ToUInt32(patchModel.RelationAddr, 16), sPortTemp);
                                    }

                                }
                            }
                            else
                            {
                                tempVal = SerialSend.ReadRegister(Convert.ToUInt32(duVal, 16), sPortTemp);
                                switch (duVal)
                                {
                                    case "80500021":
                                        tempVal |= 0x08;
                                        break;
                                    case "8050001c":
                                        tempVal |= 0x01;
                                        break;
                                    case "80200002":
                                        tempVal &= 0x7f;
                                        break;
                                    case "8020002c":
                                        tempVal |= 0x01;
                                        break;
                                    case "80500200":
                                        tempVal &= 0x0f;
                                        break;
                                    default:
                                        break;
                                }
                                //col[1] = col[1].Contains(" ") ? " 0x" + tempVal.ToString("x2") : "0x" + tempVal.ToString("x2");

                            }
                            string oldVal = col[1].Replace("0x", "").Replace(" ", "");
                            col[1] = col[1].Replace(oldVal, tempVal.ToString("x2"));
                            listStr[i] = string.Join(",", col);
                        }
                        catch (Exception ex)
                        {
                            WaitBefore.Close();
                            DevExpress.XtraEditors.XtraMessageBox.Show(ex.ToString());
                            throw;
                        }
                    }
                }
            }
            SerialSend.isDebug = true;
            WaitBefore.Close();
            msg.state = MsgSt.Success;
            msg.data = listStr;
            return msg;
        }
        /// <summary>
        /// 传入setting路径，更新参数
        /// </summary>
        /// <returns></returns>
        private XChip_Common.MsgString<List<string>> UpdateParameter(string filepath, bool stIndex = true)
        {
            XChip_Common.MsgString<List<string>> msg = new MsgString<List<string>>();
            if (!sPortTemp.IsOpen)
            {
                msg.state = MsgSt.Warn;
                msg.msg = $"可用端口未打开！";
                return msg;
            }
            var Pe_patch_dal = new parameter_export_patchManager();
            var patchList = Pe_patch_dal.GetList();
            StreamReader sr = new StreamReader(filepath, Encoding.Default);
            List<string> listStr = new List<string>();
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                listStr.Add(line);
            }
            sr.Close();
            //全局变量 0xfffd  0xfffe
            string add = "80";//  0xfffd
            string addval = string.Empty; //0xfffe
            string duVal = string.Empty; //读取的值
            int step2Start = -1;
            //onself iq 也采用这种方式进行更新
            if (stIndex)
            {
                step2Start = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("Step 2 reconfig system", StringComparison.InvariantCultureIgnoreCase) >= 0);
                #region 判断setp2的起始索引
                if (step2Start < 0)
                {
                    step2Start = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("Step 2", StringComparison.InvariantCultureIgnoreCase) >= 0);
                    if (step2Start < 0)
                    {
                        step2Start = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("Step2", StringComparison.InvariantCultureIgnoreCase) >= 0);
                    }
                }
                #endregion
            }
            else
            {
                step2Start = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("Step 2", StringComparison.InvariantCultureIgnoreCase) >= 0);
                #region 判断setp2的起始索引
                if (step2Start < 0)
                {
                    step2Start = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("Step 3", StringComparison.InvariantCultureIgnoreCase) >= 0);
                    if (step2Start < 0)
                    {
                        step2Start = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("Step 4", StringComparison.InvariantCultureIgnoreCase) >= 0);
                    }
                }
                #endregion
            }

            #region 判断sensor的起始索引
            var sensorStart = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("0xfff8", StringComparison.InvariantCultureIgnoreCase) >= 0);
            var sensorEnd = -1;
            if (sensorStart != -1)
            {
                sensorEnd = Array.FindIndex(listStr.ToArray(), sensorStart + 1, t => t.IndexOf("0xfff8", StringComparison.InvariantCultureIgnoreCase) >= 0) + 1;
            }
            else
            {
                sensorStart = Array.FindIndex(listStr.ToArray(), t => t.IndexOf("0xfff0", StringComparison.InvariantCultureIgnoreCase) >= 0);
                if (sensorStart != -1)
                {
                    sensorEnd = Array.FindIndex(listStr.ToArray(), sensorStart + 1, t => t.IndexOf("0xfff0", StringComparison.InvariantCultureIgnoreCase) >= 0) + 1;
                }
            }
            #endregion
            int patchStart = listStr.FindIndex(c => c.ToLower().Contains("patch_start"));
            int patchEnd = listStr.FindIndex(c => c.ToLower().Contains("patch_end"));
            int disableUpdateStart = listStr.FindIndex(c => c.ToLower().Contains("disable_update_start"));
            int disableUpdateEnd = listStr.FindIndex(c => c.ToLower().Contains("disable_update_end"));
            WaitBefore.Start("参数导出", "正在加载中", 60);
            SerialSend.isDebug = false;
            #region 更新逻辑
            for (int i = (step2Start < 0 ? 0 : step2Start); i < listStr.Count(); i++)
            {
                //if ((i >= startIndex && i <= endIndex) || (i >= sensorStart && i <= sensorEnd))
                if (listStr[i].ToLower().Contains("disable_update_start"))
                {
                    while (!listStr[i++].ToLower().Contains("disable_update_end"))
                    {
                        string[] col_re = listStr[i].Replace('，', ',').Split(',');
                        if (col_re.Count() > 2)
                        {
                            string colFirst = col_re.First().Trim().ToLower();
                            //过滤关键字
                            if (colFirst == "0xffff" || colFirst == "0xfff3" || colFirst == "0xfff6" || colFirst == "0xfff7" || colFirst == "0xfff8" || colFirst == "0xfff9" || colFirst == "0xfffa" || colFirst == "0xfff0" || colFirst == "0xfff1")
                            {
                                continue;
                            }
                            else if (colFirst == "0xfffd")
                            {
                                add = col_re[1].Replace("0x", "");
                            }
                            else if (colFirst == "0xfffe")
                            {
                                addval = col_re[1].Replace("0x", "");
                            }
                        }
                    };
                }
                if ((i >= sensorStart && i <= sensorEnd) || (i >= patchStart && i <= patchEnd))//跳过sensor部分和patch部分
                {
                    continue;
                }
                string[] col = listStr[i].Replace('，', ',').Split(',');
                if (col.Count() > 2)
                {
                    string colFirst = col.First().Trim().ToLower();
                    //过滤关键字
                    if (colFirst == "0xffff" || colFirst == "0xfff3" || colFirst == "0xfff6" || colFirst == "0xfff7" || colFirst == "0xfff8" || colFirst == "0xfff9" || colFirst == "0xfffa" || colFirst == "0xfff0" || colFirst == "0xfff1")
                    {
                        continue;
                    }
                    else if (colFirst == "0xfffd")
                    {
                        add = col[1].Replace("0x", "");
                    }
                    else if (colFirst == "0xfffe")
                    {
                        addval = col[1].Replace("0x", "");
                    }
                    else if (colFirst.Contains("0x") && !colFirst.Contains("//"))
                    {
                        try
                        {
                            string sonVal = colFirst.Replace("0x", "").Replace(" ", "");
                            duVal = (add + addval + sonVal.PadLeft(4, '0')).Replace("0x", "").Replace(" ", "").ToLower();
                            if (duVal.Length != 8 || duVal == "80300000" || duVal == "80300001" || duVal == "80300002" || duVal == "80300003" || duVal == "80300004"
                                 || duVal == "8014062c")
                                continue;

                            long tempVal = -1;  //加入iq 特殊处理代码

                            if (patchList.Count != 0 && patchList.Select(c => c.ReadAddr).Contains(duVal))
                            {
                                var patchModel = patchList.First(c => c.ReadAddr.Contains(duVal));

                                if (string.IsNullOrEmpty(patchModel.ConditionAddr)&&string.IsNullOrEmpty(patchModel.RelationAddr)&&!string.IsNullOrEmpty(patchModel.Val))
                                {
                                    tempVal = Convert.ToUInt32(patchModel.Val, 16);
                                }
                                else if (!string.IsNullOrEmpty(patchModel.ConditionAddr) && SerialSend.ReadRegister(Convert.ToUInt32(patchModel.ConditionAddr, 16), sPortTemp) == 0)
                                {
                                    tempVal = SerialSend.ReadRegister(Convert.ToUInt32(patchModel.ReadAddr, 16), sPortTemp);
                                }
                                else if (string.IsNullOrEmpty(patchModel.RelationAddr) && string.IsNullOrEmpty(patchModel.ConditionAddr) && !string.IsNullOrEmpty(patchModel.Bit))
                                {
                                    tempVal = Convert.ToUInt32(patchModel.Bit, 16);
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(patchModel.Bit) && patchModel.Bit.Contains("&0x7f"))
                                    {
                                        tempVal = SerialSend.ReadRegister(Convert.ToUInt32(patchModel.RelationAddr, 16), sPortTemp) & 0x7f;
                                    }
                                    else
                                    {
                                        tempVal = SerialSend.ReadRegister(Convert.ToUInt32(patchModel.RelationAddr, 16), sPortTemp);
                                    }

                                }
                            }
                            else
                            {
                                tempVal = SerialSend.ReadRegister(Convert.ToUInt32(duVal, 16), sPortTemp);
                                switch (duVal)
                                {
                                    case "80500021":
                                        tempVal |= 0x08;
                                        break;
                                    case "8050001c":
                                        tempVal |= 0x01;
                                        break;
                                    case "80200002":
                                        tempVal &= 0x7f;
                                        break;
                                    case "8020002c":
                                        tempVal |= 0x01;
                                        break;
                                    case "80500200":
                                        tempVal &= 0x0f;
                                        break;
                                    default:
                                        break;
                                }
                            }
                            string oldVal = col[1].Replace("0x", "").Replace(" ", "");
                            col[1] = col[1].Replace(oldVal, tempVal.ToString("x2"));
                            listStr[i] = string.Join(",", col);
                        }
                        catch (Exception ex)
                        {
                            WaitBefore.Close();
                            DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);
                            throw;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    continue;
                }
            }
            #endregion
            SerialSend.isDebug = true;
            WaitBefore.Close();
            msg.state = MsgSt.Success;
            msg.data = listStr;
            return msg;
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            DialogResult dr = DevExpress.XtraEditors.XtraMessageBox.Show($"选择YES保存后退出！ \r\n 选择NO直接退出！", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
            if (dr == DialogResult.No)
            {
                this.Close();
            }
            else
            {
                XChip_SettingFile_FormClosed(null, null);
            }
        }

    

        private void setPanelShowHide(int no) {
            for (int i = 0; i < 16; i++)
            {
                var str = $"panel{i}";
                Control c = this.Controls.Find(str, true)[0];
                PanelControl pan = c as PanelControl;
                pan.Visible = false;
            }

            if (no>4&&no <= 8)
            {
                onetofourPage.PageVisible = true;
                fivetoeightPage.PageVisible = true;
                ninetotwelvePage.PageVisible = false;
                thirteentosixteenPage.PageVisible = false;
                
            }
            else if (no>8&&no <= 12)
            {
                onetofourPage.PageVisible = true;
                fivetoeightPage.PageVisible = true;
                ninetotwelvePage.PageVisible = true;
                thirteentosixteenPage.PageVisible = false;
            }
            else if (no>12&&no <= 16)
            {
                onetofourPage.PageVisible = true;
                fivetoeightPage.PageVisible = true;
                ninetotwelvePage.PageVisible = true;
                thirteentosixteenPage.PageVisible = true;
            }
            else
            {
                onetofourPage.PageVisible = true;
                fivetoeightPage.PageVisible = false;
                ninetotwelvePage.PageVisible = false;
                thirteentosixteenPage.PageVisible = false;
            }
            for (int i = 0; i < no; i++)
            {
                if (i == 0)
                {
                    navigationPane1.SelectedPage = onetofourPage;
                }
                else if (i==4)
                {
                    navigationPane1.SelectedPage = fivetoeightPage;
                }
                else if (i == 8)
                {
                    navigationPane1.SelectedPage = ninetotwelvePage;
                }
                else if (i==12)
                {
                    navigationPane1.SelectedPage = thirteentosixteenPage;
                }
                var str = $"panel{i}";
                Control c = this.Controls.Find(str, true)[0];
                PanelControl pan = c as PanelControl;
                pan.Visible = true;
            }
        }

        private void textEdit1_EditValueChanged(object sender, EventArgs e)
        {
            var noTxt = int.Parse(textEdit1.Text) > 16?16: int.Parse(textEdit1.Text);
            textEdit1.Text = noTxt.ToString();
            setPanelShowHide(noTxt);
        }

        private void setting0_EditValueChanged(object sender, EventArgs e)
        {
            if (isloadAgain) return;
            var settingPath = sender as LookUpEdit;
            //BinUpdate(settingPath);
        }

        private void setting0_btn_Click(object sender, EventArgs e)
        {
            var btn = sender as DevExpress.XtraEditors.SimpleButton;
            try
            {
                var serialno = (int.Parse(btn.Tag.ToString()) - 1);
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "TXT Files(*.txt;*.c)|*.txt;*.c|All Files(*.*)|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    #region 16套文件勾选
                    switch (btn.Tag.ToString())
                    {
                        case "1":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting0);
                            }
                            break;
                        case "2":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting1);
                            }
                            break;
                        case "3":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting2);
                            }
                            break;
                        case "4":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting3);
                            }
                            break;
                        case "5":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting4);
                            }
                            break;
                        case "6":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting5);
                            }
                            break;
                        case "7":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting6);
                            }
                            break;
                        case "8":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting7);
                            }
                            break;
                        case "9":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting8);
                            }
                            break;
                        case "10":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting9);
                            }
                            break;
                        case "11":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting10);
                            }
                            break;
                        case "12":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting11);
                            }
                            break;
                        case "13":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting12);
                            }
                            break;
                        case "14":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting13);
                            }
                            break;
                        case "15":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting14);
                            }
                            break;
                        case "16":
                            {
                                SetLookEdit(openFileDialog1, serialno, setting15);
                            }
                            break;
                       
                        default:
                            break;
                    }
                    #endregion
                }
            }
            catch
            {
                WaitBefore.Close();
            }
        }
        /// <summary>
        /// setting 赋值
        /// </summary>
        /// <param name="openFileDialog1"></param>
        /// <param name="serialno"></param>
        /// <param name="setPath"></param>
        private void SetLookEdit(OpenFileDialog openFileDialog1, int serialno, LookUpEdit setPath)
        {
            if (null == SettingList_Help.SetTips16[serialno].data)
            {
                SettingList_Help.SetTips16[serialno].data = new List<TreeListValue>();
            }
           
            SettingList_Help.SetTips16[serialno].data.Add(new TreeListValue() { ValueMember = openFileDialog1.FileName, DisplayMember = Path.GetFileName(openFileDialog1.FileName) });
            setPath.Properties.DataSource = SettingList_Help.SetTips16[serialno].data;
            setPath.ItemIndex = SettingList_Help.SetTips16[serialno].data.Count() - 1;
        }
        /// <summary>
        /// common 赋值
        /// </summary>
        /// <param name="openFileDialog1"></param>
        /// <param name="serialno"></param>
        /// <param name="setPath"></param>
        private void SetComLookEdit(OpenFileDialog openFileDialog1, int serialno, LookUpEdit setPath)
        {
            if (null == SettingList_Help.SetTips16[serialno].comData)
            {
                SettingList_Help.SetTips16[serialno].comData = new List<TreeListValue>();
            }
            SettingList_Help.SetTips16[serialno].comData.Add(new TreeListValue() { ValueMember = openFileDialog1.FileName, DisplayMember = Path.GetFileName(openFileDialog1.FileName) });
            setPath.Properties.DataSource = SettingList_Help.SetTips16[serialno].comData;
            setPath.ItemIndex = SettingList_Help.SetTips16[serialno].comData.Count() - 1;
        }
        private void common0_btn_Click(object sender, EventArgs e)
        {
            var btn = sender as DevExpress.XtraEditors.SimpleButton;
            try
            {
                var serialno = (int.Parse(btn.Tag.ToString()) - 1);
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "TXT Files(*.txt;*.c)|*.txt;*.c|All Files(*.*)|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    #region 16套文件勾选
                    switch (btn.Tag.ToString())
                    {
                        case "1":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common0);
                            }
                            break;
                        case "2":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common1);
                            }
                            break;
                        case "3":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common2);
                            }
                            break;
                        case "4":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common3);
                            }
                            break;
                        case "5":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common4);
                            }
                            break;
                        case "6":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common5);
                            }
                            break;
                        case "7":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common6);
                            }
                            break;
                        case "8":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common7);
                            }
                            break;
                        case "9":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common8);
                            }
                            break;
                        case "10":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common9);
                            }
                            break;
                        case "11":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common10);
                            }
                            break;
                        case "12":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common11);
                            }
                            break;
                        case "13":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common12);
                            }
                            break;
                        case "14":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common13);
                            }
                            break;
                        case "15":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common14);
                            }
                            break;
                        case "16":
                            {
                                SetComLookEdit(openFileDialog1, serialno, common15);
                            }
                            break;

                        default:
                            break;
                    }
                    #endregion
                }
            }
            catch
            {
                WaitBefore.Close();
            }
        }

        private void setting0_all_btn_Click(object sender, EventArgs e)
        {
            var btn = sender as SimpleButton;
            string path = string.Empty;
            switch (btn.Tag.ToString())
            {
                case "1":
                    path = setting0.EditValue.ToString();
                    break;
                case "2":
                    path = setting1.EditValue.ToString();
                    break;
                case "3":
                    path = setting2.EditValue.ToString();
                    break;
                case "4":
                    path = setting3.EditValue.ToString();
                    break;
                case "5":
                    path = setting4.EditValue.ToString();
                    break;
                case "6":
                    path = setting5.EditValue.ToString();
                    break;
                case "7":
                    path = setting6.EditValue.ToString();
                    break;
                case "8":
                    path = setting7.EditValue.ToString();
                    break;
                case "9":
                    path = setting8.EditValue.ToString();
                    break;
                case "10":
                    path = setting9.EditValue.ToString();
                    break;
                case "11":
                    path = setting10.EditValue.ToString();
                    break;
                case "12":
                    path = setting11.EditValue.ToString();
                    break;
                case "13":
                    path = setting12.EditValue.ToString();
                    break;
                case "14":
                    path = setting13.EditValue.ToString();
                    break;
                case "15":
                    path = setting14.EditValue.ToString();
                    break;
                case "16":
                    path = setting15.EditValue.ToString();
                    break;
                default:
                    path = string.Empty;
                    break;
            }

            if (string.IsNullOrEmpty(path) || path.Contains("请选择"))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show($"1080配置 OS 文件路径未选择！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string tempPath = string.Empty;
            if (System.IO.Path.GetDirectoryName(path).Contains("SettingTemp"))
            {
                tempPath = System.IO.Path.GetDirectoryName(path) + "\\";
            }
            else
            {
                tempPath = System.IO.Path.GetDirectoryName(path) + "\\SettingTemp\\";
            }

            string tempName = string.Empty;
            if (Path.GetFileNameWithoutExtension(path).Contains("all"))
            {
                var t = Path.GetFileNameWithoutExtension(path);
                var end = t.IndexOf("_all");
                tempName = t.Substring(0, end) + "_all_" + DateTime.Now.ToString("MMddHHmmss");
            }
            else if (Path.GetFileNameWithoutExtension(path).Contains("iq"))
            {
                var t = Path.GetFileNameWithoutExtension(path);
                var end = t.IndexOf("_iq");
                tempName = t.Substring(0, end) + "_all_" + DateTime.Now.ToString("MMddHHmmss");
            }
            else
            {
                tempName = Path.GetFileNameWithoutExtension(path) + "_all_" + DateTime.Now.ToString("MMddHHmmss");
            }


            //确定目录是否存在
            if (!Directory.Exists(tempPath))
            {
                //创建它不存在的目录
                Directory.CreateDirectory(tempPath);
            }

            var pSaveFilePath = $"{tempPath}{tempName}{Path.GetExtension(path)}";
            if (!File.Exists(pSaveFilePath))//必须判断要复制的文件是否存在
            {
                File.Copy(path, pSaveFilePath, true);//三个参数分别是源文件路径，存储路径，若存储路径有相同文件是否替换
            }
            //更新OS
            var msg = UpdateParameter(pSaveFilePath);
            if (msg.state == MsgSt.Success)
            {
                if (File.Exists(pSaveFilePath))
                {
                    File.Delete(pSaveFilePath);
                }
                File.WriteAllLines(pSaveFilePath, msg.data, Encoding.Default);
                switch (btn.Tag.ToString())
                {
                    case "1":
                        SettingList_Help.SetTips16[0].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting0.Properties.DataSource = SettingList_Help.SetTips16[0].data;
                        setting0.ItemIndex = SettingList_Help.SetTips16[0].data.Count() - 1;
                        break;
                    case "2":
                        SettingList_Help.SetTips16[1].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting1.Properties.DataSource = SettingList_Help.SetTips16[1].data;
                        setting1.ItemIndex = SettingList_Help.SetTips16[1].data.Count() - 1;
                        break;
                    case "3":
                        SettingList_Help.SetTips16[2].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting2.Properties.DataSource = SettingList_Help.SetTips16[2].data;
                        setting2.ItemIndex = SettingList_Help.SetTips16[2].data.Count() - 1;
                        break;
                    case "4":
                        SettingList_Help.SetTips16[3].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting3.Properties.DataSource = SettingList_Help.SetTips16[3].data;
                        setting3.ItemIndex = SettingList_Help.SetTips16[3].data.Count() - 1;
                        break;
                    case "5":
                        SettingList_Help.SetTips16[4].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting4.Properties.DataSource = SettingList_Help.SetTips16[4].data;
                        setting4.ItemIndex = SettingList_Help.SetTips16[4].data.Count() - 1;
                        break;
                    case "6":
                        SettingList_Help.SetTips16[5].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting5.Properties.DataSource = SettingList_Help.SetTips16[5].data;
                        setting5.ItemIndex = SettingList_Help.SetTips16[5].data.Count() - 1;
                        break;
                    case "7":
                        SettingList_Help.SetTips16[6].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting6.Properties.DataSource = SettingList_Help.SetTips16[6].data;
                        setting6.ItemIndex = SettingList_Help.SetTips16[6].data.Count() - 1;
                        break;
                    case "8":
                        SettingList_Help.SetTips16[7].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting7.Properties.DataSource = SettingList_Help.SetTips16[7].data;
                        setting7.ItemIndex = SettingList_Help.SetTips16[7].data.Count() - 1;
                        break;
                    case "9":
                        SettingList_Help.SetTips16[8].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting8.Properties.DataSource = SettingList_Help.SetTips16[8].data;
                        setting8.ItemIndex = SettingList_Help.SetTips16[8].data.Count() - 1;
                        break;
                    case "10":
                        SettingList_Help.SetTips16[9].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting9.Properties.DataSource = SettingList_Help.SetTips16[9].data;
                        setting9.ItemIndex = SettingList_Help.SetTips16[9].data.Count() - 1;
                        break;
                    case "11":
                        SettingList_Help.SetTips16[10].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting10.Properties.DataSource = SettingList_Help.SetTips16[10].data;
                        setting10.ItemIndex = SettingList_Help.SetTips16[10].data.Count() - 1;
                        break;
                    case "12":
                        SettingList_Help.SetTips16[11].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting11.Properties.DataSource = SettingList_Help.SetTips16[11].data;
                        setting11.ItemIndex = SettingList_Help.SetTips16[11].data.Count() - 1;
                        break;
                    case "13":
                        SettingList_Help.SetTips16[12].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting12.Properties.DataSource = SettingList_Help.SetTips16[12].data;
                        setting12.ItemIndex = SettingList_Help.SetTips16[12].data.Count() - 1;
                        break;
                    case "14":
                        SettingList_Help.SetTips16[13].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting13.Properties.DataSource = SettingList_Help.SetTips16[13].data;
                        setting13.ItemIndex = SettingList_Help.SetTips16[13].data.Count() - 1;
                        break;
                    case "15":
                        SettingList_Help.SetTips16[14].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting14.Properties.DataSource = SettingList_Help.SetTips16[14].data;
                        setting14.ItemIndex = SettingList_Help.SetTips16[14].data.Count() - 1;
                        break;
                    case "16":
                        SettingList_Help.SetTips16[15].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting15.Properties.DataSource = SettingList_Help.SetTips16[15].data;
                        setting15.ItemIndex = SettingList_Help.SetTips16[15].data.Count() - 1;
                        break;
                    default:
                        break;
                }
            }
            else
            {
                XtraMessageBox.Show($"更新错误：{msg.msg}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void setting0_iq_btn_Click(object sender, EventArgs e)
        {
            var btn = sender as SimpleButton;
            string path = string.Empty;
            switch (btn.Tag.ToString())
            {
                case "1":
                    path = setting0.EditValue.ToString();
                    break;
                case "2":
                    path = setting1.EditValue.ToString();
                    break;
                case "3":
                    path = setting2.EditValue.ToString();
                    break;
                case "4":
                    path = setting3.EditValue.ToString();
                    break;
                case "5":
                    path = setting4.EditValue.ToString();
                    break;
                case "6":
                    path = setting5.EditValue.ToString();
                    break;
                case "7":
                    path = setting6.EditValue.ToString();
                    break;
                case "8":
                    path = setting7.EditValue.ToString();
                    break;
                case "9":
                    path = setting8.EditValue.ToString();
                    break;
                case "10":
                    path = setting9.EditValue.ToString();
                    break;
                case "11":
                    path = setting10.EditValue.ToString();
                    break;
                case "12":
                    path = setting11.EditValue.ToString();
                    break;
                case "13":
                    path = setting12.EditValue.ToString();
                    break;
                case "14":
                    path = setting13.EditValue.ToString();
                    break;
                case "15":
                    path = setting14.EditValue.ToString();
                    break;
                case "16":
                    path = setting15.EditValue.ToString();
                    break;
                default:
                    path = string.Empty;
                    break;
            }
            if (string.IsNullOrEmpty(path) || path.Contains("请选择"))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show($"1080配置 IQ 文件路径未选择！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string tempPath = string.Empty;
            if (System.IO.Path.GetDirectoryName(path).Contains("SettingTemp"))
            {
                tempPath = System.IO.Path.GetDirectoryName(path) + "\\";
            }
            else
            {
                tempPath = System.IO.Path.GetDirectoryName(path) + "\\SettingTemp\\";
            }
            string tempName = string.Empty;
            if (Path.GetFileNameWithoutExtension(path).Contains("iq"))
            {
                var t = Path.GetFileNameWithoutExtension(path);
                var end = t.IndexOf("_iq");
                tempName = t.Substring(0, end) + "_iq_" + DateTime.Now.ToString("MMddHHmmss");
            }
            else if (Path.GetFileNameWithoutExtension(path).Contains("all"))
            {
                var t = Path.GetFileNameWithoutExtension(path);
                var end = t.IndexOf("_all");
                tempName = t.Substring(0, end) + "_iq_" + DateTime.Now.ToString("MMddHHmmss");
            }
            else
            {
                tempName = Path.GetFileNameWithoutExtension(path) + "_iq_" + DateTime.Now.ToString("MMddHHmmss");
            }
            //确定目录是否存在
            if (!Directory.Exists(tempPath))
            {
                //创建它不存在的目录
                Directory.CreateDirectory(tempPath);
            }

            var pSaveFilePath = $"{tempPath}{tempName}{Path.GetExtension(path)}";
            if (!File.Exists(pSaveFilePath))//必须判断要复制的文件是否存在
            {
                File.Copy(path, pSaveFilePath, true);//三个参数分别是源文件路径，存储路径，若存储路径有相同文件是否替换
            } 
            //更新IQ
            var msg = UpdateParameterNewIQ(pSaveFilePath);
            if (msg.state == MsgSt.Success)
            {
                if (File.Exists(pSaveFilePath))
                {
                    File.Delete(pSaveFilePath);
                }
                File.WriteAllLines(pSaveFilePath, msg.data, Encoding.Default);
                switch (btn.Tag.ToString())
                {
                    case "1":
                        SettingList_Help.SetTips16[0].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting0.Properties.DataSource = SettingList_Help.SetTips16[0].data;
                        setting0.ItemIndex = SettingList_Help.SetTips16[0].data.Count() - 1;
                        break;
                    case "2":
                        SettingList_Help.SetTips16[1].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting1.Properties.DataSource = SettingList_Help.SetTips16[1].data;
                        setting1.ItemIndex = SettingList_Help.SetTips16[1].data.Count() - 1;
                        break;
                    case "3":
                        SettingList_Help.SetTips16[2].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting2.Properties.DataSource = SettingList_Help.SetTips16[2].data;
                        setting2.ItemIndex = SettingList_Help.SetTips16[2].data.Count() - 1;
                        break;
                    case "4":
                        SettingList_Help.SetTips16[3].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting3.Properties.DataSource = SettingList_Help.SetTips16[3].data;
                        setting3.ItemIndex = SettingList_Help.SetTips16[3].data.Count() - 1;
                        break;
                    case "5":
                        SettingList_Help.SetTips16[4].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting4.Properties.DataSource = SettingList_Help.SetTips16[4].data;
                        setting4.ItemIndex = SettingList_Help.SetTips16[4].data.Count() - 1;
                        break;
                    case "6":
                        SettingList_Help.SetTips16[5].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting5.Properties.DataSource = SettingList_Help.SetTips16[5].data;
                        setting5.ItemIndex = SettingList_Help.SetTips16[5].data.Count() - 1;
                        break;
                    case "7":
                        SettingList_Help.SetTips16[6].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting6.Properties.DataSource = SettingList_Help.SetTips16[6].data;
                        setting6.ItemIndex = SettingList_Help.SetTips16[6].data.Count() - 1;
                        break;
                    case "8":
                        SettingList_Help.SetTips16[7].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting7.Properties.DataSource = SettingList_Help.SetTips16[7].data;
                        setting7.ItemIndex = SettingList_Help.SetTips16[7].data.Count() - 1;
                        break;
                    case "9":
                        SettingList_Help.SetTips16[8].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting8.Properties.DataSource = SettingList_Help.SetTips16[8].data;
                        setting8.ItemIndex = SettingList_Help.SetTips16[8].data.Count() - 1;
                        break;
                    case "10":
                        SettingList_Help.SetTips16[9].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting9.Properties.DataSource = SettingList_Help.SetTips16[9].data;
                        setting9.ItemIndex = SettingList_Help.SetTips16[9].data.Count() - 1;
                        break;
                    case "11":
                        SettingList_Help.SetTips16[10].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting10.Properties.DataSource = SettingList_Help.SetTips16[10].data;
                        setting10.ItemIndex = SettingList_Help.SetTips16[10].data.Count() - 1;
                        break;
                    case "12":
                        SettingList_Help.SetTips16[11].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting11.Properties.DataSource = SettingList_Help.SetTips16[11].data;
                        setting11.ItemIndex = SettingList_Help.SetTips16[11].data.Count() - 1;
                        break;
                    case "13":
                        SettingList_Help.SetTips16[12].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting12.Properties.DataSource = SettingList_Help.SetTips16[12].data;
                        setting12.ItemIndex = SettingList_Help.SetTips16[12].data.Count() - 1;
                        break;
                    case "14":
                        SettingList_Help.SetTips16[13].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting13.Properties.DataSource = SettingList_Help.SetTips16[13].data;
                        setting13.ItemIndex = SettingList_Help.SetTips16[13].data.Count() - 1;
                        break;
                    case "15":
                        SettingList_Help.SetTips16[14].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting14.Properties.DataSource = SettingList_Help.SetTips16[14].data;
                        setting14.ItemIndex = SettingList_Help.SetTips16[14].data.Count() - 1;
                        break;
                    case "16":
                        SettingList_Help.SetTips16[15].data.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        setting15.Properties.DataSource = SettingList_Help.SetTips16[15].data;
                        setting15.ItemIndex = SettingList_Help.SetTips16[15].data.Count() - 1;
                        break;
                    default:
                        break;
                }
            }
            else
            {
                XtraMessageBox.Show($"更新错误：{msg.msg}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void common0_all_btn_Click(object sender, EventArgs e)
        {
            var btn = sender as SimpleButton;
            string path = string.Empty;
            switch (btn.Tag.ToString())
            {
                case "1":
                    path = common0.EditValue.ToString();
                    break;
                case "2":
                    path = common1.EditValue.ToString();
                    break;
                case "3":
                    path = common2.EditValue.ToString();
                    break;
                case "4":
                    path = common3.EditValue.ToString();
                    break;
                case "5":
                    path = common4.EditValue.ToString();
                    break;
                case "6":
                    path = common5.EditValue.ToString();
                    break;
                case "7":
                    path = common6.EditValue.ToString();
                    break;
                case "8":
                    path = common7.EditValue.ToString();
                    break;
                case "9":
                    path = common8.EditValue.ToString();
                    break;
                case "10":
                    path = common9.EditValue.ToString();
                    break;
                case "11":
                    path = common10.EditValue.ToString();
                    break;
                case "12":
                    path = common11.EditValue.ToString();
                    break;
                case "13":
                    path = common12.EditValue.ToString();
                    break;
                case "14":
                    path = common13.EditValue.ToString();
                    break;
                case "15":
                    path = common14.EditValue.ToString();
                    break;
                case "16":
                    path = common15.EditValue.ToString();
                    break;
                default:
                    path = string.Empty;
                    break;
            }

            if (string.IsNullOrEmpty(path) || path.Contains("请选择"))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show($"1080配置 OS 文件路径未选择！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string tempPath = string.Empty;
            if (System.IO.Path.GetDirectoryName(path).Contains("SettingTemp"))
            {
                tempPath = System.IO.Path.GetDirectoryName(path) + "\\";
            }
            else
            {
                tempPath = System.IO.Path.GetDirectoryName(path) + "\\SettingTemp\\";
            }

            string tempName = string.Empty;
            if (Path.GetFileNameWithoutExtension(path).Contains("all"))
            {
                var t = Path.GetFileNameWithoutExtension(path);
                var end = t.IndexOf("_all");
                tempName = t.Substring(0, end) + "_all_" + DateTime.Now.ToString("MMddHHmmss");
            }
            else if (Path.GetFileNameWithoutExtension(path).Contains("iq"))
            {
                var t = Path.GetFileNameWithoutExtension(path);
                var end = t.IndexOf("_iq");
                tempName = t.Substring(0, end) + "_all_" + DateTime.Now.ToString("MMddHHmmss");
            }
            else
            {
                tempName = Path.GetFileNameWithoutExtension(path) + "_all_" + DateTime.Now.ToString("MMddHHmmss");
            }


            //确定目录是否存在
            if (!Directory.Exists(tempPath))
            {
                //创建它不存在的目录
                Directory.CreateDirectory(tempPath);
            }

            var pSaveFilePath = $"{tempPath}{tempName}{Path.GetExtension(path)}";
            if (!File.Exists(pSaveFilePath))//必须判断要复制的文件是否存在
            {
                File.Copy(path, pSaveFilePath, true);//三个参数分别是源文件路径，存储路径，若存储路径有相同文件是否替换
            }
            //更新OS
            var msg = UpdateParameter(pSaveFilePath);
            if (msg.state == MsgSt.Success)
            {
                if (File.Exists(pSaveFilePath))
                {
                    File.Delete(pSaveFilePath);
                }
                File.WriteAllLines(pSaveFilePath, msg.data, Encoding.Default);
                switch (btn.Tag.ToString())
                {
                    case "1":
                        SettingList_Help.SetTips16[0].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common0.Properties.DataSource = SettingList_Help.SetTips16[0].comData;
                        common0.ItemIndex = SettingList_Help.SetTips16[0].comData.Count() - 1;
                        break;
                    case "2":
                        SettingList_Help.SetTips16[1].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common1.Properties.DataSource = SettingList_Help.SetTips16[1].comData;
                        common1.ItemIndex = SettingList_Help.SetTips16[1].comData.Count() - 1;
                        break;
                    case "3":
                        SettingList_Help.SetTips16[2].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common2.Properties.DataSource = SettingList_Help.SetTips16[2].comData;
                        common2.ItemIndex = SettingList_Help.SetTips16[2].comData.Count() - 1;
                        break;
                    case "4":
                        SettingList_Help.SetTips16[3].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common3.Properties.DataSource = SettingList_Help.SetTips16[3].comData;
                        common3.ItemIndex = SettingList_Help.SetTips16[3].comData.Count() - 1;
                        break;
                    case "5":
                        SettingList_Help.SetTips16[4].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common4.Properties.DataSource = SettingList_Help.SetTips16[4].comData;
                        common4.ItemIndex = SettingList_Help.SetTips16[4].comData.Count() - 1;
                        break;
                    case "6":
                        SettingList_Help.SetTips16[5].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common5.Properties.DataSource = SettingList_Help.SetTips16[5].comData;
                        common5.ItemIndex = SettingList_Help.SetTips16[5].comData.Count() - 1;
                        break;
                    case "7":
                        SettingList_Help.SetTips16[6].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common6.Properties.DataSource = SettingList_Help.SetTips16[6].comData;
                        common6.ItemIndex = SettingList_Help.SetTips16[6].comData.Count() - 1;
                        break;
                    case "8":
                        SettingList_Help.SetTips16[7].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common7.Properties.DataSource = SettingList_Help.SetTips16[7].comData;
                        common7.ItemIndex = SettingList_Help.SetTips16[7].comData.Count() - 1;
                        break;
                    case "9":
                        SettingList_Help.SetTips16[8].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common8.Properties.DataSource = SettingList_Help.SetTips16[8].comData;
                        common8.ItemIndex = SettingList_Help.SetTips16[8].comData.Count() - 1;
                        break;
                    case "10":
                        SettingList_Help.SetTips16[9].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common9.Properties.DataSource = SettingList_Help.SetTips16[9].comData;
                        common9.ItemIndex = SettingList_Help.SetTips16[9].comData.Count() - 1;
                        break;
                    case "11":
                        SettingList_Help.SetTips16[10].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common10.Properties.DataSource = SettingList_Help.SetTips16[10].comData;
                        common10.ItemIndex = SettingList_Help.SetTips16[10].comData.Count() - 1;
                        break;
                    case "12":
                        SettingList_Help.SetTips16[11].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common11.Properties.DataSource = SettingList_Help.SetTips16[11].comData;
                        common11.ItemIndex = SettingList_Help.SetTips16[11].comData.Count() - 1;
                        break;
                    case "13":
                        SettingList_Help.SetTips16[12].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common12.Properties.DataSource = SettingList_Help.SetTips16[12].comData;
                        common12.ItemIndex = SettingList_Help.SetTips16[12].comData.Count() - 1;
                        break;
                    case "14":
                        SettingList_Help.SetTips16[13].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common13.Properties.DataSource = SettingList_Help.SetTips16[13].comData;
                        common13.ItemIndex = SettingList_Help.SetTips16[13].comData.Count() - 1;
                        break;
                    case "15":
                        SettingList_Help.SetTips16[14].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common14.Properties.DataSource = SettingList_Help.SetTips16[14].comData;
                        common14.ItemIndex = SettingList_Help.SetTips16[14].comData.Count() - 1;
                        break;
                    case "16":
                        SettingList_Help.SetTips16[15].comData.Add(new TreeListValue() { ValueMember = pSaveFilePath, DisplayMember = Path.GetFileName(pSaveFilePath) });
                        common15.Properties.DataSource = SettingList_Help.SetTips16[15].comData;
                        common15.ItemIndex = SettingList_Help.SetTips16[15].comData.Count() - 1;
                        break;
                    default:
                        break;
                }
            }
            else
            {
                XtraMessageBox.Show($"更新错误：{msg.msg}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
    }
}